<?php

/**
 * RP System
 *
 * @version 1.0
 * @copyright 2004 Ron Planken
 */

class raid_role {

	function get($raid_id = -1, $class_role_id = -1, $raid_role_id = -1, $role_id = -1) {

		global $dbh;

		if ($raid_id == -1) {
			$query ="SELECT  rr.id
							,rr.raid_id
							,rr.class_role_id
							,rr.role_id
							,rr.max_main
							,cr.id as 'class_role_id'
							,cr.class_id
							,cr.role_id
							,cr.name as 'class_role_name'
							,r.name as 'role_name'
							,r.small_picture as 'role_picture'
							,r.id as 'general_id'
					   FROM raid_role rr
				  LEFT JOIN class_role cr ON cr.id = rr.class_role_id
				  LEFT JOIN role r ON r.id = rr.role_id
				   ORDER by rr.class_role_id";
		} else {
			$query ="SELECT  rr.id
							,rr.raid_id
							,rr.class_role_id
							,rr.role_id
							,rr.max_main
							,cr.id as 'class_role_id'
							,cr.class_id
							,cr.role_id
							,cr.name as 'class_role_name'
							,r.name as 'role_name'
							,r.small_picture as 'role_picture'
							,r.id as 'general_id'
					   FROM raid_role rr
				  LEFT JOIN class_role cr ON cr.id = rr.class_role_id
				  LEFT JOIN role r ON r.id = rr.role_id
							";
			if ($raid_role_id > 0) {
				$query .= " WHERE rr.id = $raid_role_id";
			}
			if ($raid_id > 0) {
				$query .= " WHERE rr.raid_id = $raid_id";
			}
			if ($class_role_id > 0) {
				$query .= " AND rr.class_role_id = $class_role_id";
			}
			if ($role_id > 0) {
				$query .= " AND rr.role_id = $role_id";
			}

		}

		$raid_roles = selectMultiQuery($query, $dbh);

		return $raid_roles;
	}

	function save($id = 0, $raid_id, $class_role_id, $role_id, $max_main) {

		global $dbh;

		$id = secure_int($id);
		$raid_id = secure_int($raid_id);
		$class_role_id = secure_int($class_role_id);
		$role_id = secure_int($role_id);
		$max_main = secure_int($max_main);
		

		if ($id == 0) {
			$query ="INSERT INTO raid_role
						   ( raid_id
						   ,class_role_id
						   ,role_id
						   ,max_main)
					VALUES ( $raid_id
						    ,$class_role_id
						    ,$role_id
						    ,$max_main)
							";
			$result = InsertQuery($query, $dbh);

			$status = mysql_insert_id();

		} else {
			$query ="UPDATE raid_role
						SET max_main = $max_main
					  WHERE id = $id
							";

			$status = UpdateQuery($query, $dbh);
		}

		return $status;

	}

	function remove($player_id = 0) {

		global $dbh;

		$remover_id = $_SESSION['uid'];

		//$query ="UPDATE player
		//				SET removed = 1
		//				   ,date_removed = Now()
		//				   ,remover_id = $remover_id
		//			  WHERE player_id = $player_id
		//					";
		//$status = UpdateQuery($query, $dbh);

		
		
		
		return $status;
	}

}
?>